package app.server.project.main.service.db.entity.user;

import app.server.project.core.syndb.SynDBMgr;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Transient;
import lombok.Data;
import org.hibernate.annotations.Comment;

@Data
@Entity(name = "solana_slot")
@TableName("solana_slot")
@Comment(value = "solana区块数据")
public class SolanaSlotEntity {

    @Id
    @Column(name = "id")
    @Comment("用户主键")
    @TableId("id")
    private long id;

    @TableField("slot")
    @Column(name = "slot")
    @Comment("slot")
    private long slot;

    @TableField("block_time")
    @Column(name = "block_time")
    @Comment("区块时间")
    private long blockTime;

    @TableField("block_hash")
    @Column(name = "block_hash")
    @Comment("区块hash")
    private String blockHash;
    @JsonIgnore
    @Transient
    @TableField(exist = false)
    private boolean synDb = false;

    public static SolanaSlotEntity of(long id) {
        SolanaSlotEntity userInfoEntity = new SolanaSlotEntity();
        userInfoEntity.setId(id);
        userInfoEntity.setSynDb(true);
        return userInfoEntity;
    }

    public void setBlockTime(long blockTime) {
        this.blockTime = blockTime;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(SolanaSlotEntity::getBlockTime, this);
    }

    public void setSlot(long slot) {
        this.slot = slot;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(SolanaSlotEntity::getSlot, this);
    }

    public void setBlockHash(String blockHash) {
        this.blockHash = blockHash;
        if (!this.synDb) return;
        SynDBMgr.addChangeData(SolanaSlotEntity::getBlockHash, this);
    }


}
